<?php

namespace Biz\model\activity;

use Doraemon\pockets\datebase\BaseDbModel;
use Medoo\Medoo;

class ActivityDoubleElevenLog extends BaseDbModel
{
    const _CONFIG_FILE_ = 'db_shop';

    const _CONFIG_SELECT_ = 'db_activity';

    const _DATABASE_ = 'shop_activity';

    const _TABLE_NAME = 'activity_double_eleven_log';


    public static function addData($uid, $type, $title, $desc, $sort = 0)
    {
        $data = [
            'uid' => $uid,
            'sort' => $sort,
            'type' => $type,
            'title' => $title,
            'desc' => $desc,
            'addtime' => date('Y-m-d H:i:s'),
        ];
        return self::insert($data)->rowcount();
    }

    public static function getList($offset, $size)
    {
        return self::select(['id','uid','title','addtime'], [
            'ORDER' => ['sort' => 'DESC', 'id' => 'DESC'],
            "LIMIT" => [$offset, $size]
        ]);
    }

    public static function getCount($where = [])
    {
        return self::count($where);
    }

    public static function groupUser()
    {
        $result = self::select(['uid', 'count' => Medoo::raw("count('uid')")], [
            'GROUP' => ['uid']
        ]);
        return $result ? : [];
    }

}